-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle missing scheme in animated image rule #545
Handle missing scheme in animated image rule #545
Conversation
…date the url is existing
…nly instead of duplicated inside other functions
…ror_when_image_lacks_scheme
includes/helper-functions.php
Outdated
$file = edac_url_add_scheme_if_not_existing( $filename ); | ||
$url_exists = edac_url_exists( $file ); | ||
// if the https version does not exist, try http. | ||
if ( false === $url_exists ) { | ||
$file = edac_url_add_scheme_if_not_existing( $filename, 'http' ); | ||
$url_exists = edac_url_exists( $file ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this over the weekend and I want to just do away with the nested if logic here and instead assume it will always have only what the site protocal is since the page it loads on would dictate it. Thoughts on dropping the internal if here that falls back to http
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can remove this logic check.
includes/helper-functions.php
Outdated
* @return string The filename unchanged if it doesn't look like a URL, or with a scheme added if it does. | ||
*/ | ||
function edac_url_add_scheme_if_not_existing( string $file, string $site_protocol = 'https' ): string { | ||
if ( str_starts_with( $file, $site_protocol ) || ! str_starts_with( $file, '//' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check if a protocol doesn't exist at all? Right now a URL like this isn't caught.
<img src="assets.rewardstyle.com/images/search/350.gif" />
The capability is supporting urls that are neither relative not protocol-relative. It's an edge case for sure but no harm in adding support for it.
…tive urls as well Also adds an explicit list of valid schemes as well to support more edge cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL's like this assets.rewardstyle.com/images/search/350.gif
are still being opened without a protocol.
Here is the warning:
[26-Mar-2024 16:39:23 UTC] PHP Warning: fopen(rewardstyle.com/images/search/350.gif): Failed to open stream: No such file or directory in /Users/stevejones/Documents/Repositories/accessibility-checker/includes/helper-functions.php on line 950
…obust Thanks to the newly added tests for catching my last change here as being a change that had downstream effects :)
…obust Thanks to the newly added tests for catching my last change here as being a change that had downstream effects :)
…causes_error_when_image_lacks_scheme' into william/544/animage_image_check_causes_error_when_image_lacks_scheme # Conflicts: # includes/helper-functions.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to merge.
The rule that handles detection of animated gifs and webp images was causing an error on sites when the image src was missing a scheme. This PR solves for that by creating a helper function to add a scheme and verify the URL is accessible before opening the file to analyse it's frames.
Fixes: #544